/*
	Copyright (c) 2009, SpLib.net
  	All rights reserved.
  	
  	Author:6spring
  	About:iterator，用于各容器
*/

package SpLib.std
{
	import SpLib.std.utils;
	
	public class iterator
	{
		private var m_pPrev:iterator = null;
		private var m_pNext:iterator = null;
		
		public var m_Key:*;
		public var m_Data:*;
		
		public function iterator(data:*,key:* = null)
		{
			m_Data = data;		
			m_Key = key;
		}
		
		public function set next(n:iterator):void
		{
			if(n!=null)
			{
				n.m_pPrev = this;
				n.m_pNext = m_pNext;
			}
			
			if(m_pNext!=null)
			{
				m_pNext.m_pPrev = n;
			}
			
			m_pNext = n;
		}
		
		public function get next():iterator
		{
			return m_pNext;
		}
		
		public function set prev(p:iterator):void
		{
			if(p!=null)
			{
				p.m_pNext = this;
				p.m_pPrev = m_pPrev;
			}
			
			if(m_pPrev!=null)
			{
				m_pPrev.m_pNext = p;
			}
			
			m_pPrev = p;
		}
		
		public function get prev():iterator
		{
			return m_pPrev;
		}
		
		public function unlink():void
		{
			if(m_pPrev!=null)
			{
				m_pPrev.m_pNext = m_pNext;
			}
			
			if(m_pNext!=null)
			{
				m_pNext.m_pPrev = m_pPrev;
			}
			
			m_pPrev = m_pNext = null;
		}
		
		public function release():void
		{
			unlink();
			
			m_Key = null;			
			m_Data = null;
		}
	}
}